// To parse this JSON data, do
//
//     final complaint = complaintFromJson(jsonString);

import 'dart:convert';

import '../../../data/models/auth/user.dart';

Complaint complaintFromJson(String str) => Complaint.fromJson(json.decode(str));

String complaintToJson(Complaint data) => json.encode(data.toJson());

class Complaint {
  final String? complaintId;
  final String? createdBy;
  final String? managerResponded;
  final String complaint;
  final String? state;
  final DateTime? createAt;
  final String? respondedBy;
  final User? user;

  Complaint({
    this.complaintId,
    this.createdBy,
    this.managerResponded,
    required this.complaint,
    this.state,
    this.createAt,
    this.respondedBy,
    this.user,
  });

  Complaint copyWith({
    String? complaintId,
    String? createdBy,
    dynamic managerResponded,
    String? complaint,
    String? state,
    DateTime? createAt,
    dynamic respondedBy,
    User? user,
  }) =>
      Complaint(
        complaintId: complaintId ?? this.complaintId,
        createdBy: createdBy ?? this.createdBy,
        managerResponded: managerResponded ?? this.managerResponded,
        complaint: complaint ?? this.complaint,
        state: state ?? this.state,
        createAt: createAt ?? this.createAt,
        respondedBy: respondedBy ?? this.respondedBy,
        user: user ?? this.user,
      );

  factory Complaint.fromJson(Map<String, dynamic> json) => Complaint(
    complaintId: json["complaint_id"]?.toString(),
    createdBy: json["created_by"]?.toString(),
    managerResponded: json["manager_responded"]?.toString(),
    complaint: json["complaint"].toString(),
    state: json["state"]?.toString(),
    createAt: DateTime.parse(json["create_at"]),
    respondedBy: json["responded_by"]?.toString(),
    user: User.fromJson(json["user"]),
  );

  Map<String, dynamic> toJson() => {
    "complaint_id": complaintId,
    "created_by": createdBy,
    "manager_responded": managerResponded,
    "complaint": complaint,
    "state": state,
    "create_at": createAt?.toIso8601String(),
    "responded_by": respondedBy,
    "user": user?.toJson(),
  };
}

